<template>
<view>
<view class="word_box_div">
	<view class="word_box">
		<label class="name_box">姓</label>名：</view>
	<view class="inp_box">
		<input class="inp_word" @input="inpName" type="text" :value="name" placeholder="请输入您的姓名">
	</view>
</view>
<view class="word_box_div">
	<view class="word_box">联系电话：</view>
	<view class="inp_box">
		<input class="inp_word" @input="inpTel" maxlength="11" type="number" :value="tel" placeholder="请输入您的电话号码">
	</view>
</view>
<view class="word_box_div">
	<view class="word_box">
		<label class="name_box">地</label>址：</view>
	<view class="inp_box">
		<region-picker @change="bindRegionChange" :value="region" :custom-item="customItem">
			<view class="picker" v-if="region.length!=0">
				{{region[0]}}-{{region[1]}}-{{region[2]}}
			</view>
			<view v-else class="red_word">点我选择地址</view>
		</region-picker>
	</view>
</view>
<view class="mem_box">
	<view class="mem_item line_box" @tap="changeMem">
		<view class="mem_tit">普通会员</view>
		<view class="mem_pric">￥{{memInfo[0].money}}/年</view>
		<image class="jb_img" v-if="mem_dj==1" mode="aspectFill" src="/static/pages/image/jiaobiao_icn.png"></image>
	</view>
	<view class="mem_item" @tap="changeMem">
		<view class="mem_tit">高级会员</view>
		<view class="mem_pric">￥{{memInfo[1].money}}/年</view>
		<image class="jb_img" v-if="mem_dj==2" mode="aspectFill" src="/static/pages/image/jiaobiao_icn.png"></image>
	</view>
</view>
<view class="ag_box">
	<view class="ag_img" @tap="click_agButt">
		<block v-if="is_ok==0">
			<image mode="aspectFill" src="/static/pages/image/weixuanze_btn.png"></image>
		</block>
		<block v-if="is_ok==1">
			<image mode="aspectFill" src="/static/pages/image/xuanze_btn.png"></image>
		</block>

	</view>
	<view class="ag_word">阅读并同意<label data-ty="1" @tap="click_ag">会员协议</label>条款</view>
</view>
<view class="clear"></view>
<view class="mem_intr">权益说明：<label data-ty="2" @tap="click_ag">点击查看会员权益</label></view>
<button class="reg_butt" @tap="click_reginButt">立即注册</button>
</view>
</template>

<script>
var app = getApp();

export default {
  data() {
    return {
      region: [],
      name: '',
      tel: '',
      mem_dj: 1,
      mem_tips: ['普通会员说明', '高级会员说明'],
      memInfo: [],
      // 选择的会员价格
      money: '',
      addrStr: '',
      //是否同意协议
      is_ok: 0,
      customItem: ""
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getMemInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    //会员切换
    changeMem: function () {
      var that = this;

      if (that.mem_dj == 1) {
        that.setData({
          mem_dj: 2,
          money: that.memInfo[1].money
        });
      } else {
        that.setData({
          mem_dj: 1,
          money: that.memInfo[0].money
        });
      }
    },
    //点击是否同意协议
    click_agButt: function () {
      var that = this;

      if (that.is_ok == 0) {
        that.setData({
          is_ok: 1
        });
      } else {
        that.setData({
          is_ok: 0
        });
      }
    },
    //获取姓名
    inpName: function (e) {
      var that = this;
      console.log('输入：', e.detail.value);
      that.setData({
        name: e.detail.value
      });
    },
    //获取电话
    inpTel: function (e) {
      var that = this;
      console.log(e.detail.value);
      that.setData({
        tel: e.detail.value
      });
    },
    bindRegionChange: function (e) {
      console.log('picker发送选择改变，携带值为', e.detail.value);
      this.setData({
        region: e.detail.value
      });
    },
    //获取会员参数
    getMemInfo: function () {
      var that = this;
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          m: "monai_market",
          r: "home.index.vipset"
        },
        success: function (res) {
          console.log('会员参数返回：', res.data);
          that.setData({
            memInfo: res.data.data,
            money: res.data.data[0].money
          });
        },
        fail: function (res) {}
      });
    },
    //点击查看会员协议
    click_ag: function (e) {
      var ty = e.currentTarget.dataset.ty;
      wx.navigateTo({
        url: '/pagesA/member/agInfo/agInfo?ty=' + ty
      });
    },
    //点击立即注册按钮
    click_reginButt: function () {
      var that = this;
      console.log(that.name);

      if (that.name != '' && that.name != null) {
        if (that.tel != '' && that.tel != null) {
          if (that.region.length != 0) {
            var addr = that.region[0] + that.region[1] + that.region[2];

            if (that.is_ok == 1) {
              app.globalData.util.request({
                url: "entry/wxapp/Paybuyvip",
                data: {
                  m: "monai_market",
                  // r: "home.index.get_area",
                  uid: app.globalData.getuid(),
                  level: that.mem_dj,
                  money: that.money,
                  nickname: that.name,
                  phone: that.tel,
                  address: addr
                },
                success: function (res) {
                  console.log('注册成功：', res.data);
                  wx.requestPayment({
                    timeStamp: res.data.data.timeStamp,
                    nonceStr: res.data.data.nonceStr,
                    package: res.data.data.package,
                    signType: "MD5",
                    paySign: res.data.data.paySign,
                    success: function (a) {
                      wx.showModal({
                        title: "提示",
                        content: "支付成功",
                        showCancel: !1,
                        success: function (a) {
                          // app.util.request({
                          //     url: "entry/wxapp/Api",
                          //     data: {
                          //         m: "monai_market",
                          //         r: "store.send_tel_news",
                          //         formid: t.detail.formId,
                          //         uid: wx.getStorageSync("uid"),
                          //         tel_type: 2
                          //     }
                          // }), 
                          a.confirm && wx.reLaunch({
                            url: "/pages/index/index"
                          });
                        }
                      });
                    },
                    fail: function (a) {
                      wx.showToast({
                        title: "支付失败",
                        icon: "none",
                        duration: 2e3
                      });
                    }
                  });
                },
                fail: function (res) {}
              });
            } else {
              wx.showToast({
                title: '请同意会员协议',
                icon: "none"
              });
            }
          } else {
            wx.showToast({
              title: '请选择地址',
              icon: "none"
            });
          }
        } else {
          wx.showToast({
            title: '请输入电话',
            icon: "none"
          });
        }
      } else {
        wx.showToast({
          title: '请输入姓名',
          icon: "none"
        });
      } // wx.navigateTo({
      //   url: '../asMember/asMember',
      // })

    }
  }
};
</script>
<style>
@import "./member.css";
</style>